
	

set more off

graph drop _all

	** consumption over net import 

	use Data/sample_income_discountoc_angle.dta, clear


	gen net_import= import-export
	** pre discounted price
	gen price = peakoffpeak_base
	
	replace price = FIT_price if net_import <=0
	

	keep if hour >=8 & hour<=17 

	egen cut_netimport = cut(net_import), at(-6(0.1)6)

	replace FIT_t="T" if FIT_t =="S"

	gen income = PV_production * price

	gen net_hourly_cost =  peakoffpeak_price * importkWh - FIT_price * exportkWh 

	gen nethourly_cost_kWh = net_hourly_cost/consumption_kWh
	
	reg consumption  hour_hdd* hour_cdd*, nocons
	predict cons_hat
	
	gen cons_notemp = consumption - cons_hat 
		
	
	reg consumption hour_hdd* hour_cdd* hourfeed* 
	predict cons_1hat
	
	gen cons_noFIThour = consumption - cons_1hat

		
	reg consumption hour_hdd* hour_cdd* ghi hourfeed* 
	predict cons_2hat
	
	
	gen cons_noirradtemp = consumption - cons_2hat
	
	
	
	egen cut_PV = cut(PV_production), at(0(1)6)

		
		drop if income==.


	collapse (mean) nethourly income importkWh exportkWh cons* PV_production FIT_price price virtualincome pexport_oc pexport_FIT pimport_price temp_interp  , by(cut_net FIT_type)

	
	
	label variable cut_net "Net import"
	
	
	 
		twoway (connected consumption cut_net if FIT_t=="P" , lcolor(gs0) msymbol(none) lpattern(solid) lwidth(thick) ) ///
	(connected consumption cut_net if FIT_t=="T" , msymbol(none) lpattern(longdash) lwidth(thick) lcolor(gs0) ) ///
		(connected consumption cut_net if FIT_t=="F" ,  msymbol(none) lpattern(shortdash) lwidth(thick) lcolor(gs0)) ///
	 (pcarrowi 1.8 0 1.8 -0.75 , lcolor(gs0))  (pcarrowi 1.8 0 1.8 0.75 , lcolor(gs0))  ///
	if  cut_net>=-2 & cut_net <=1, scheme(s2mono) graphregion(color(white))  ///
	ytitle("Mean hourly consumption (kWh)", size(medlarge)) ///
	text(2 0 "Sales", place(w) size(medlarge))  text(2 0 "Purchases", place(e) size(medlarge)) ///
	xscale(range(-2.1 1))  xlabel(-2 "2" -1 "1" 0 "0" 1 "1" ) ///
	 yscale(range(0 2)) ylabel(0(0.5)1.5, angle(horixontal)) ///
	 xtitle("kWh", size(med)) xline(0) legend(order(1 "60 FIT" 2 "1:1 & 25 FIT" 3 "8 FIT") region(style(none) lcolor(none)) cols(3)) name(cons) ///
	 title("Panel A. Consumption and sales" " " " ", position(11) size(medlarge) ring(7)) 
	
	

	 
		twoway (connected cons_notemp cut_net if FIT_t=="P" , lcolor(gs0) msymbol(none) lpattern(solid) lwidth(thick) ) ///
		(connected cons_notemp cut_net if FIT_t=="T" , msymbol(none) lpattern(longdash) lwidth(thick) lcolor(gs0) ) ///
	(connected cons_notemp cut_net if FIT_t=="F" ,  msymbol(none) lpattern(shortdash) lwidth(thick) lcolor(gs0)) ///
	(pcarrowi 1.8 0 1.8 -0.75 , lcolor(gs0))  (pcarrowi 1.8 0 1.8 0.75 , lcolor(gs0))  ///
	if  cut_net>=-2 & cut_net <=1 , legend(off) scheme(s2mono) graphregion(color(white))  ///
	ytitle("") xscale(range(-2.1 1))  xlabel(-2 "2" -1 "1" 0 "0" 1 "1" ) ///
	 text(2 0 "Sales", place(w) size(medlarge))  text(2 0 "Purchases", place(e) size(medlarge)) ///
	 yscale(range(0 2)) ylabel(0(0.5)1.5, angle(horixontal)) ///
	 xtitle("kWh", size(med)) xline(0) name(consnotemp) ///
	 title("Panel B. Consumption and sales" "removing temperature" " ", position(11) size(medlarge) ring(7)) 
	 
	

  grc1leg cons consnotemp
  
  
  	graph export Results/Andrea/cons_net_temp.pdf, replace

	
	
	
	
	 
		twoway (connected cons_noFIThour cut_net if FIT_t=="P" , lcolor(gs0) msymbol(none) lpattern(solid) lwidth(thick) ) ///
		(connected cons_noFIThour cut_net if FIT_t=="T" , msymbol(none) lpattern(longdash) lwidth(thick) lcolor(gs0) ) ///
	(connected cons_noFIThour cut_net if FIT_t=="F" ,  msymbol(none) lpattern(shortdash) lwidth(thick) lcolor(gs0)) ///
	(pcarrowi 1.8 0 1.8 -0.75 , lcolor(gs0))  (pcarrowi 1.8 0 1.8 0.75 , lcolor(gs0))  ///
	if  cut_net>=-2 & cut_net <=1 , legend(order(1 "60 FIT" 2 "1:1 & 25 FIT" 3 "8 FIT") region(style(none) lcolor(none)) cols(3))  scheme(s2mono) graphregion(color(white))  ///
	ytitle("") xscale(range(-2.1 1))  xlabel(-2 "2" -1 "1" 0 "0" 1 "1" ) ///
	 text(2 0 "Sales", place(w) size(medlarge))  text(2 0 "Purchases", place(e) size(medlarge)) ///
	 yscale(range(0 2)) ylabel(0(0.5)1.5, angle(horixontal)) ///
	 xtitle("kWh", size(med)) xline(0) name(consnotempFIT) ///
	 title("Panel A. Consumption and sales" "removing temperature and" "FIT x hour effects", position(11) size(medlarge) ring(7)) 
	 
	

	 
		twoway (connected cons_noirradtemp cut_net if FIT_t=="P" , lcolor(gs0) msymbol(none) lpattern(solid) lwidth(thick) ) ///
		(connected cons_noirradtemp cut_net if FIT_t=="T" , msymbol(none) lpattern(longdash) lwidth(thick) lcolor(gs0) ) ///
	(connected cons_noirradtemp cut_net if FIT_t=="F" ,  msymbol(none) lpattern(shortdash) lwidth(thick) lcolor(gs0)) ///
	(pcarrowi 1.8 0 1.8 -0.75 , lcolor(gs0))  (pcarrowi 1.8 0 1.8 0.75 , lcolor(gs0))  ///
	if  cut_net>=-2 & cut_net <=1 , legend(off) scheme(s2mono) graphregion(color(white))  ///
	ytitle("") xscale(range(-2.1 1))  xlabel(-2 "2" -1 "1" 0 "0" 1 "1" ) ///
	 text(2 0 "Sales", place(w) size(medlarge))  text(2 0 "Purchases", place(e) size(medlarge)) ///
	 yscale(range(0 2)) ylabel(0(0.5)1.5, angle(horixontal)) ///
	 xtitle("kWh", size(med)) xline(0) name(consnotempirrad) ///
	 title("Panel B. Consumption and sales" "removing temperature" "FIT x hour effects and sunshine", position(11) size(medlarge) ring(7)) 
	 
	

	
  grc1leg consnotempFIT consnotempirrad
  
  
  	graph export Results/Andrea/cons_contributions.pdf, replace

	
	
	
	
